#pragma once

#include <string>
#include <string.h>
#include "qbprotocol/include/ssLoginProto.h"
#include "qbkernel/include/qb_base.h"
#include "../core.h"

#define kLoginConnect		0x0001		// 登录网络连接状态
#define kHttpKernel         0x0002      // http事件

#pragma warning(disable:4251)
namespace qb
{
	/*< ip/port */
	struct S_CORE_EXPORT tIPAdressPort
	{
		tIPAdressPort()
		{
			strIPAdress = "";
			uPort = 0;
		}
		std::string strIPAdress;
		uint32_t uPort;
	};

	/*< 用户基本信息 */
	struct S_CORE_EXPORT tUserData
	{
		std::string strUserID;			// 用户ID
		std::string strAccount;		    // 账号
		std::string strRawPassword;	    // 原始密码
		std::string strPassword;	    // 密码
		std::string strCookie;			// cookie
		std::string strCompanyId;       // companyid
		std::string strMac;				// mac地址
	};

	class S_CORE_EXPORT loginData
	{
	public:
		static loginData& instance();

	public:
		int32_t& ConnectID();

		const tIPAdressPort& GetServerLoginAddress() const;
		void SetServerLoginAddress(const std::string& strIP, uint32_t uPort);

		const tIPAdressPort& GetGatewayLoginAddress() const;
		void SetGatewayLoginAddress(const std::string& strIP, uint32_t uPort);

		NetStatus GetCurrentStatus() const;
		void SetCurrentStatus(NetStatus eStatus);

		void SetLoginAck(const xLoginLgnSvrProAck_t& ack);
		xLoginLgnSvrProAck_t& GetLoginAck();

		void SetReLogin(bool bReLogin);

		bool IsLoggedin() const;
		bool IsLoginning() const;
		bool IsReLogin() const;

		void ResetLoginData();

		tUserData& UserInfo();

	private:
		loginData();
		~loginData();

		void ResetLoginAck();

	private:
		int32_t                 m_connect_id;
		tUserData               m_UserData;
		tIPAdressPort			m_serverAddressPort;
		tIPAdressPort			m_gatewayAddressPort;
		NetStatus				m_eStatus;
		xLoginLgnSvrProAck_t    m_xLgnAckBody;
		bool					m_bReLogin;
	};

}